﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Chats;
using VK.Comm;
using VK.Casemeet.Employees;

namespace VK.Casemeet.Web.Admin.Chats
{
    public partial class ChatEdit : System.Web.UI.Page
    {
        public int chatID = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="客服列表",Url="/Admin/Chats/ChatList.aspx"},
                new MapPath{ Text="编辑",Url="#"}
            };

            chatID = Util.GetQueryInt("ChatID");

            if (!IsPostBack)
            {
                //GoodsHelper.BindDeprDDL(ddlDepr, OptionType.Select);

                LoadData();
            }
        }

        internal void LoadData()
        {
            if (chatID != 0)
            {
                ChatEntity chat = ChatBLL.GetChat(chatID);
                txtNumber.Text = chat.Number;
                txtName.Text = chat.Name;
                txtCreated.Text = Util.FormatDateTime(chat.Created, DateTimeStyle.ShortDate2);
                txtSort.Text = chat.Sort.ToString();
                chkIsEnable.Checked = chat.IsEnable;
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            ChatEntity chat = LoadEntity();
            chat.ChatID = chatID;

            if (ChatBLL.UpdateChat(chat) > 0)
            {
                Message.Msg(this.Page, CS.MsgEditSuccess, MessageType.Success);
            }
            else
            {
                Message.Msg(this.Page, CS.MsgEditFailure, MessageType.Failure);
            }
            LoadData();
        }

        protected ChatEntity LoadEntity()
        {
            ChatEntity chat = ChatBLL.GetChat(chatID);
            chat.Number = txtNumber.Text;
            chat.Name = txtName.Text;
            chat.Created = Util.ConverDateTime(txtCreated.Text);
            chat.Sort = int.Parse(txtSort.Text);
            chat.IsEnable = chkIsEnable.Checked;

            return chat;
        }
    }
}